//
//  PeiSongDingDanViewController.m
//  Experss
//
//  Created by wmwMAC on 17/8/11.
//  Copyright © 2017年 嗯，大葱. All rights reserved.
//

#import "PeiSongDingDanViewController.h"
#import "DingDanList2Cell.h"
#import "PublicMapVController.h"
#import "NoJieDanViewController.h"
#import "DingDanDetailViewController2.h"

@interface PeiSongDingDanViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)NSArray *dataArray;

@end

@implementation PeiSongDingDanViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _dataArray = @[
  @[@{@"1":@"2"},@{@"3":@"4"}],@[@{@"1":@"2"},@{@"1":@"9"}],@[@{@"1":@"2"},@{@"1":@"8"}]
  ];
    [self configureNaBar];
    [self configureVCon];
}
//配置导航栏
- (void)configureNaBar {
    self.navigationItem.title = @"订单列表";
    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
    
}
//配置视图控制器
- (void)configureVCon {
    
    self.view.backgroundColor = KShouYeBg;
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, kScreen_Height-50) style:(UITableViewStyleGrouped)];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = kSpNone;
    _tableView.backgroundColor = KShouYeBg;
    [self.view addSubview:_tableView];
    [_tableView registerNib:[UINib nibWithNibName:@"DingDanList2Cell" bundle:nil] forCellReuseIdentifier:@"DingDanList2Cell"];
    
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _dataArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSArray *teA = _dataArray[section];
    return  teA.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 60;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 70;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 70;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *bgV = [[UIView alloc] init];
    bgV.backgroundColor = KShouYeBg;
    
    UIView *bgV22 = [[UIView alloc] initWithFrame:CGRectMake(0, 10, kScreen_Width - 0,50)];
    bgV22.backgroundColor = [UIColor whiteColor];
    [bgV addSubview:bgV22];
    
    UIView *bgV2 = [[UIView alloc] initWithFrame:CGRectMake(20, 49, kScreen_Width - 40, 1)];
    bgV2.backgroundColor = KShouYeBg;
    [bgV22 addSubview:bgV2];
    
    
    UIImageView *imageV = [[UIImageView alloc] init];
    imageV.frame = CGRectMake(20, 17, 15, 15);
    imageV.image = [UIImage imageNamed:@"ddlb_shijian"];
    [bgV22 addSubview:imageV];
    
    
    UILabel *la1 = [[UILabel alloc] init];
    la1.text = @"2017-09-28 17:23";
    la1.textColor = [UIColor blackColor];
    la1.frame = CGRectMake(CGRectGetMaxX(imageV.frame)+13, 15, 150, 20);
    la1.font = kFont14;
    [bgV22 addSubview:la1];
    
    
    
    UILabel *lb2 = [[UILabel alloc] initWithFrame:CGRectMake(kScreen_Width- 150, 15, 130, 20)];
    lb2.font = kFont15;
    lb2.text = @"¥20.0";
    lb2.textAlignment = NSTextAlignmentRight;
    lb2.textColor = KQiangGour;
    [bgV22 addSubview:lb2];
    
    
    
    return bgV;
    
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *bgV = [[UIView alloc] init];
    bgV.backgroundColor = [UIColor whiteColor];
    
    UIButton *btn1 = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn1.frame = CGRectMake(20, 10, (kScreen_Width- 20-20-20)/2, 40);
    [btn1 setTitle:@"订单详情" forState:(UIControlStateNormal)];
    [btn1 setTitleColor:[UIColor lightGrayColor] forState:(UIControlStateNormal)];
    [btn1 setBackgroundColor: [UIColor whiteColor]];
    btn1.titleLabel.font = kFont15;
    btn1.layer.masksToBounds = YES;
    btn1.layer.cornerRadius = 20;
    btn1.layer.borderColor = KShouYeBg.CGColor;
    btn1.layer.borderWidth= 1.0f;
    [bgV addSubview:btn1];
   
    UIButton *btn2 = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn2.frame = CGRectMake(CGRectGetMaxX(btn1.frame)+20, 10, (kScreen_Width- 20-20-20)/2, 40);
    [btn2 setTitle:@"立即接单" forState:(UIControlStateNormal)];
    [btn2 setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    [btn2 setBackgroundImage:[UIImage imageNamed:@"bg1"] forState:(UIControlStateNormal)];
    btn2.titleLabel.font = kFont15;
    btn2.layer.masksToBounds = YES;
    btn2.layer.cornerRadius = 20;
    btn2.layer.borderColor = KShouYeBg.CGColor;
    btn2.layer.borderWidth= 1.0f;
    [bgV addSubview:btn2];
    
    
    btn1.tag = 101;
    btn2.tag = 102;
    [btn1 addTarget:self action:@selector(handleHearAndFooBtntAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    
    [btn2 addTarget:self action:@selector(handleHearAndFooBtntAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    return bgV;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    DingDanList2Cell *cell = [tableView dequeueReusableCellWithIdentifier:@"DingDanList2Cell"];
    cell.selectionStyle = kSeNone;
    if (indexPath.row == 1) {
        cell.shagndianLB.text = @"我也不知道名字的商店";
        cell.imageV.highlighted = YES;
        cell.addressLB.text = @" 不知道要送到什么地方才可以啊";
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    PublicMapVController *pub = [[PublicMapVController alloc] init];
    pub.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:pub animated:YES];
}
- (void)handleHearAndFooBtntAction:(UIButton *)sender {
    if (sender.tag == 101) {
        //订单详情
        DingDanDetailViewController2 *vc = [[DingDanDetailViewController2 alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
    }
    if (sender.tag == 102) {
        //立即接单
        NoJieDanViewController *vc = [[NoJieDanViewController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
    }
}
@end
